package com.security.it.authentication.controller;

import com.security.it.authentication.common.ValidateCodeProcessorHolder;
import com.security.it.core.enums.ValidateCodeType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class ValidateCodeController {

    @Autowired
    private ValidateCodeProcessorHolder validateCodeProcessor;

    @GetMapping("/code/{type}")
    public void createCode(HttpServletRequest request, HttpServletResponse response, @PathVariable("type") String type) throws Exception {
        ValidateCodeType codeType = ValidateCodeType.getByCode(type);
        validateCodeProcessor.findValidateCodeProcessor(codeType)
                .create(new ServletWebRequest(request, response), codeType);
    }

}
